package cc.autoapi.pucong.liteflow.design.core.configuration;

import cc.autoapi.pucong.liteflow.design.core.exception.DesignException;
import cc.autoapi.pucong.liteflow.design.mobal.DesignUser;
import cc.autoapi.pucong.liteflow.design.mobal.HeaderDesignUser;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * UI权限拦截器
 *
 * @author pucong
 */
public interface AuthorizationInterceptor {


    /**
     * 是否需要登录
     *
     * @return true 需要登录， false 不需要登录
     */
    default boolean requireLogin() {
        return false;
    }

    /**
     * 是否只读
     * @return
     */
    default boolean readonly() {
        return false;
    }

    /**
     * 是否启用设计器
     * @return
     */
    default boolean isenable() {
        return false;
    }

    /**
     * 根据Token获取User对象
     *
     * @param request
     * @return 登录成功后返回DesignUser对象
     * @throws DesignException 登录失败抛出
     */
    default HeaderDesignUser getUserByHeader(HttpServletRequest request) throws DesignException {
        return null;
    }

    /**
     * 根据用户名，密码登录
     *
     * @param username 用户名
     * @param password 密码
     * @return 登录成功后返回DesignUser对象
     * @throws DesignException 登录失败抛出
     */
    default DesignUser loginCheck(String username, String password) throws DesignException {
        return null;
    }

    /**
     * 退出登录
     *
     * @param request
     */
    default void logout(HttpServletRequest request) {

    }

    /**
     * 是否登录
     *
     * @param request
     * @param response
     * @param handlerMethod
     */
    default boolean checkLogin(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) {
        return true;
    }
}
